﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Muccu
{
   public class MinAttribute:ArgumentValidationAttribute
    {
       public MinAttribute(float min)
       {
           this.Min = min;
           this.ErrorMessage = string.Format("Argument should at least be {0}", min);
       }
        public float Min { get; set; }

        public override bool ServerValidate(object value)
        {
            float val = (float)value;
            return val <= Min;
        }

        public override string ClientValidate
        {
            get
            {
                return @"function(val, messages){
var min = " + Min + @"; 
    var isValid = (val <= min);
    if(!isValid)messages.push(""" + ErrorMessage + "\"); return isValid;}";
            }
        }
    }
}
